package com.edu.exam.entity.examination.paper;

import com.edu.exam.enums.InvigilationAssignmentStatus;
import com.edu.exam.enums.InvigilationAssignmentMode;
import com.edu.exam.enums.InvigilationAssignmentDetailStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 监考安排实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：invigilation_assignment
 *
 * <p>监考安排实体，记录监考任务的基本信息和安排状态。
 * 包含安排详情、冲突记录、解决方案等完整信息。</p>
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InvigilationAssignment {

    /**
     * 安排ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 安排名称
     */
    @Column(name = "assignment_name", length = 100, nullable = false, unique = true)
    private String assignmentName;

    /**
     * 考试计划ID
     */
    @Column(name = "exam_schedule_id", length = 32, nullable = false)
    private String examScheduleId;

    /**
     * 安排状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "assignment_status", length = 20, nullable = false)
    private InvigilationAssignmentStatus assignmentStatus;

    /**
     * 安排模式
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "assignment_mode", length = 20, nullable = false)
    private InvigilationAssignmentMode assignmentMode;

    /**
     * 开始时间
     */
    @Column(name = "start_time", nullable = false)
    private LocalDateTime startTime;

    /**
     * 结束时间
     */
    @Column(name = "end_time", nullable = false)
    private LocalDateTime endTime;

    /**
     * 监考员数量
     */
    @Column(name = "invigilator_count", nullable = false)
    private Integer invigilatorCount;

    /**
     * 考场编号
     */
    @Column(name = "venue_code", length = 50)
    private String venueCode;

    /**
     * 考场名称
     */
    @Column(name = "venue_name", length = 200)
    private String venueName;

    /**
     * 考试科目
     */
    @Column(name = "exam_subject", length = 100)
    private String examSubject;

    /**
     * 考试类型
     */
    @Column(name = "exam_type", length = 50)
    private String examType;

    /**
     * 应考人数
     */
    @Column(name = "student_count")
    private Integer studentCount;

    /**
     * 特殊要求
     */
    @Column(name = "special_requirements", columnDefinition = "TEXT")
    private String specialRequirements;

    /**
     * 安排优先级
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 预算费用
     */
    @Column(name = "budget_amount")
    private Double budgetAmount;

    /**
     * 实际费用
     */
    @Column(name = "actual_amount")
    private Double actualAmount;

    /**
     * 安排备注
     */
    @Column(name = "assignment_remarks", length = 500)
    private String assignmentRemarks;

    /**
     * 创建人ID
     */
    @Column(name = "created_by", length = 32, nullable = false)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新人ID
     */
    @Column(name = "updated_by", length = 32)
    private String updatedBy;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 版本号
     */
    @Version
    @Column(name = "version", nullable = false)
    private Integer version;

    /**
     * 安排详情列表
     */
    @OneToMany(mappedBy = "assignment", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<InvigilationAssignmentDetail> assignmentDetails;

    /**
     * 冲突记录列表
     */
    @OneToMany(mappedBy = "assignment", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<AssignmentConflict> conflicts;


    }